Skip to content

Conversation

@davidadzgi
Copy link
Contributor

With these changes, it becomes possible to add custom children to the signature.

With this, I was able to sign using XAdES.

By adding the XAdES node as a child and including the reference to SignedProperties, this allows the XAdES node within the signature to be signed, and it adds both references to the generated signature itself.

Example:

final sig = SignedXml();
    sig.addReference("//sum1:RegistroAlta", ["http://www.w3.org/2000/09/xmldsig#enveloped-signature"], "http://www.w3.org/2001/04/xmlenc#sha256");
    sig.addReference("//xades:SignedProperties", ["http://www.w3.org/TR/2001/REC-xml-c14n-20010315"], "http://www.w3.org/2001/04/xmlenc#sha256");
    sig.keyInfoProvider = X509DataKeyInfo(publicCetrificate: File('clave_publica.pem').readAsBytesSync());
    sig.signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
    sig.canonicalizationAlgorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
    sig.signingCert = File("clave_publica.pem").readAsBytesSync();
    sig.signingKey = File("clave_privada.pem").readAsBytesSync();
    sig.addCustomSignatureChild(xmlXades);
    sig.computeSignature(xml, opts: {
      "prefix": "ds",
      "attrs": {
        "Id": idFirma,
      },
    });

@davidadzgi davidadzgi marked this pull request as ready for review April 15, 2025 16:33
@scribetw scribetw self-assigned this Apr 21, 2025
@scribetw scribetw added the enhancement New feature or request label Apr 21, 2025
@scribetw scribetw requested review from Copilot and scribetw April 21, 2025 16:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (1)
  • lib/src/signed_xml.dart: Language not supported

@scribetw scribetw merged commit b64fb9e into rikulo:master Apr 23, 2025
2 checks passed
@scribetw
Copy link
Collaborator

scribetw commented Apr 23, 2025

Thanks for the pull request!
I'm not familiar with XAdES, but the changes seem okay to me.

@davidadzgi
Copy link
Contributor Author

Thanks for accept the pull request!!

@davidadzgi davidadzgi deleted the custom_signature_nodes branch April 23, 2025 15:36
@davidadzgi davidadzgi restored the custom_signature_nodes branch April 23, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants